#cmake_minimum_required(VERSION 2.8)
CMAKE_MINIMUM_REQUIRED(VERSION 2.8)

MACRO(source_group_by_dir all_files strip_path)
	if(MSVC)
		foreach(single_file ${${all_files}})
			STRING(REGEX REPLACE "(${strip_path})/(.*)$" \\2 relative_fpath ${single_file})
			STRING(REGEX MATCH "^(.*)/(.*)\\.[^.]*$" dummy ${relative_fpath})
			#MESSAGE()
			SET(file_path ${CMAKE_MATCH_1})
			STRING(REPLACE "/" "\\" file_group_name ${file_path})
			SOURCE_GROUP(${file_group_name} FILES ${single_file})
		endforeach (single_file)
	endif(MSVC)
ENDMACRO()

FILE(GLOB_RECURSE test_include "${CMAKE_SOURCE_DIR}/include/*.h")
source_group_by_dir(test_include "${CMAKE_SOURCE_DIR}/include")

FILE(GLOB_RECURSE test_header *.h)
source_group_by_dir(test_header ${CMAKE_CURRENT_SOURCE_DIR})

FILE(GLOB_RECURSE test_cxx "${CMAKE_CURRENT_SOURCE_DIR}/*.c*")
source_group_by_dir(test_cxx ${CMAKE_CURRENT_SOURCE_DIR})

INCLUDE_DIRECTORIES(${PROJECT_SOURCE_DIR}/include ${CMAKE_CURRENT_SOURCE_DIR})
MESSAGE(STATUS ${PROJECT_SOURCE_DIR})
MESSAGE(STATUS ${CMAKE_CURRENT_SOURCE_DIR})

SET(SOURCE_FILES ${test_include} ${test_header} ${test_cxx})
SET(LIBRARY_OUTPUT_PATH ${PROJECT_BINARY_DIR}/lib)
# gen shared library
ADD_LIBRARY(test SHARED ${SOURCE_FILES})
#SET_TARGET_PROPERTIES(test PROPERTIES VERSION 1.2 SOVERSION 1)
# gen static library
ADD_LIBRARY(test_static STATIC ${SOURCE_FILES})
SET_TARGET_PROPERTIES(test_static PROPERTIES OUTPUT_NAME "test")

# @VS env only gen either "shard" or "static"
# @vmware ubuntu can't set PROPERTIES VERSION to link so.x.x
#  at shared folder which locate at win os
#  beacaus diff win file-system  
#  see https://blog.csdn.net/aflyeaglenku/article/details/50697219
#  solve https://stackoverflow.com/questions/29115323/how-to-build-linux-shared-libraries-in-windows-hard-disk-using-linux-based-platf
